package com.example.teesystem.entityDto;

import com.example.teesystem.common.cache.CourseCache;
import com.example.teesystem.entity.Chapter;
import com.example.teesystem.entity.Knowledge;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.util.List;

/**
 * @author : NieYaShi
 * @version : v1.0
 * @createTime : 2022/5/14 15:15
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class KnowledgeBriefMessage {
    private Integer id;
    private Integer courseId;
    private String courseName;
    private Integer chapterId;
    private String chapterMessage;
    private Integer type;
    private String typeStr;
    private String message;

    public KnowledgeBriefMessage(Knowledge knowledge, List<Chapter> chapterList){
        BeanUtils.copyProperties(knowledge, this);
        this.courseName = CourseCache.courseMap.get(courseId).getName();

        for (Chapter chapter : chapterList){
            if (chapter.getId().equals(chapterId)){
                this.chapterMessage = chapter.getMessage();
            }
        }

        if (type == 0){
            this.typeStr = "知识";
        }else if (type == 1){
            this.typeStr = "能力";
        }else {
            this.typeStr = "素质";
        }
    }
}
